package com.netwit.common.config;

import com.netwit.common.prop.DataSourceMappersProperties;
import com.netwit.common.utils.YamlUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Map;

@Configuration
public class DataSourceMapperConfig {

    @Value("${mappers.location:dbapi.yml}")
    private String yamlSource;
    
    @SuppressWarnings("unchecked")
    @Bean
    public DataSourceMappersProperties dataSourceMappersProperties() {
        DataSourceMappersProperties properties = new DataSourceMappersProperties();
        properties.setMap((Map<String, Object>) YamlUtil.getMap(this.yamlSource).get("mappers"));
        return properties;
    }

}